<template>
	<view class="zone">
		<Header title="余额明细" color="#fff"></Header>
		<view class="main">
			<view class="list">
				<scroll-view scroll-y class="scrollbox" @scrolltolower="scrolltolower()">
					<view class="item" v-for="(item,index) in listdata" :key="index">
						<view class="left">
							<p>{{item.remark}}</p>
							<p>{{item.created_at}}</p>
						</view>
						<view class="right">{{item.operation_type == 1?'+':'-'}}{{item.money}}</view>
					</view>		

					<view class="empty" v-if="listdata == ''">
						<image src="http://img.cpgm.cc/wkxxz/static/public/empty.png" mode="widthFix" />
						<text>数据为空</text>
					</view>
					<u-loadmore v-else :status="status" :icon-type="iconType" :load-text="loadText" />			
				</scroll-view>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:'',
				listdata:[],
				page:1,
				max_page:1,
				status: 'loadmore',
				iconType: 'flower',
				loadText: {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '没有更多了'
				},
			};
		},
		onLoad(){
			this.getmoneyDetailList()
		},
		methods: {
			scrolltolower(){
				if (this.page >= this.max_page){
					this.status = 'nomore' 
					return;
				}
				
				this.status = 'loading';
				this.page = ++this.page;
				this.getmoneyDetailList()
				setTimeout(() => {
					if (this.page > this.max_page || this.page == this.max_page) this.status = 'nomore';
					else this.status = 'loading';
				}, 500)
			},
			async getmoneyDetailList(){
				let res = await this.$http.index.moneyDetailList({
					page:this.page
				})
				this.list = res.data
				this.max_page = res.page
				this.listdata = [...this.listdata , ...this.list]
				if (this.page > this.max_page || this.page == this.max_page) this.status = 'nomore';
			},
		},
	}
</script>

<style lang="less">
.zone {
	background: linear-gradient(180deg, #0477FD 0%, #7AFDCF 100%);
	min-height: 100vh;
}
.main {
	padding: 10px;
}


.list {
	padding: 10px 0;
}

.scrollbox {
	height: calc(100vh - 100px);

	.item {
		background: rgba(255, 255, 255, 0.8);
		border-radius: 8px;
		padding: 10px;
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-bottom: 8px;

		.left {
			p:nth-child(1) {
				color: #131314;
				font-size: 14px;
				font-weight: 600;
			}
			p:nth-child(2) {
				color: #333333;
				font-size: 12px;
				opacity: 0.8;
				margin-top: 4px;
			}
		}

		.right {
			font-size: 14px;
			font-weight: 600;
			color: #333333;
		}
	}
}

</style>
